const { app , BrowserWindow ,ipcMain, globalShortcut, Menu} = require('electron');
const path = require('path')
const { default: WinState} = require('electron-win-state')
const createWindow = () => {
    const WinStateall = new WinState({
      defaultWidth: 1000,
      defaultHeight: 800
    })
    const win = new BrowserWindow({
      // 自定义窗口状态
       ...WinStateall.winOptions,
       webPreferences: {
        // 定义预加载的JS
        preload: path.resolve(__dirname,'./preload/index.js')
       }
    })

    win.loadURL('http://localhost:5173')
    win.webContents.openDevTools()
    WinStateall.manage(win)
}
app.whenReady().then(() => {
  createWindow()
  app.on('window-all-closed', () => { // 窗口全部关闭时退出
    // process主进程对象
    if (process.platform !== 'darwin') {
        app.quit()
    }
    })
  app.on('activate', () => { 
      if (BrowserWindow.getAllWindows().length === 0) { // 没有窗口激活
          createWindow() // 创建窗口
      }
  })
  // console.log(app.getAppPath('music')) // 获取应用目录
  app.on('browser-window-blur'), () => {
      console.log('browser-window-blur')

  }
  app.on('browser-window-focus'), () => {
      console.log('browser-window-focus')
  }
  app.on('before-quit', () => { // 退出前触发
      console.log('quit')
  })
})